include debug_utils.e
public include euqt_config.e  --edit in  debug or release to look first

include std/dll.e
include std/machine.e
include std/types.e

include std/io.e
include std/error.e
include std/math.e
include std/text.e
include std/sequence.e

--~ public include defs.e
public include defs.e
include wrap_helpers.e

--****
--<<LEVELTOC depth=2>>
--you can still easily crash euqt by sending the wrong object to the wrong routine.
--most routines expect a QWidget* type as the first parameter.
--this can usually be a mainwindow as well.
--eventually it should all "just work" the way you'd expect.
--
--routines marked experimental may not currently be wrapper or be limited in some way


--**
--handle to the euqt shared lib

export atom hEuQt = 0



--need to make this a commandline option or a defined word in euqt_config.e
-- release is a problem with Qt 4.50b1 anyway
sequence ddir="debugsrc",  rdir="releasesrc"
sequence lookdirs= {
        "../src/euqt"& libext
        ,"../src/debugsrc/euqt"& libext
        , "../../src/debugsrc/euqt"& libext
        , "../../../src/debugsrc/euqt"& libext
	, "./src/euqt"& libext
        }
hEuQt = open_dll("euqt.dll")  --installed on path somewhere
if hEuQt = 0 then
	--add an if exists test
    ifdef DEBUGLIB then
	 --is not changing subsequences
	 lookdirs = replace_all(lookdirs, "drdir", ddir)
    elsedef
	 lookdirs = replace_all(lookdirs, "drdir", rdir)
    end ifdef
	hEuQt = open_dll(lookdirs) --from examples debug/release
	if hEuQt = 0 then
	    hEuQt = open_dll({"../../src/euqt"& libext,"../../../src/euqt"& libext}) --from tools
	end if


    if hEuQt = 0 then
	crash("EuQt dynamic library was not found")
    end if
end if

--would be nice to know which dll was actually loaded
--should be able to use hEuQt to find out somehow

--**
-- stdcall on windows
public function callback(integer rid)
	ifdef WINDOWS then
		return call_back({'+', rid})
	elsedef
		return call_back(rid)
	end ifdef
end function


constant
	hQtPlugin_info = define_c_func(hEuQt, stdcall&"qt_plugin_info", {}, CP),
	hQtVersion_info = define_c_func(hEuQt, stdcall&"qt_version_info", {}, CP),
	hQtWidget_info = define_c_func(hEuQt, stdcall&"qt_widget_info", {P}, CP),
	hQtApp = define_c_func(hEuQt, stdcall&"qt_app", {}, P),
	hQtClipboard = define_c_func(hEuQt, stdcall&"qt_clipboard", {}, P),
	hQtSetText = define_c_proc(hEuQt, stdcall&"qt_setText", {P, CP}),
	hQtAppendText = define_c_proc(hEuQt, stdcall&"qt_appendText", {P, CP}),
	hQtText = define_c_func(hEuQt, stdcall&"qt_text", {P}, CP),
	hQtSimpleWidget = define_c_func(hEuQt, stdcall&"qt_simpleWidget", {P}, P),

	hQtInit = define_c_func(hEuQt, stdcall&"qt_init", {I, P}, P),
	hQtInit_noGUI = define_c_func(hEuQt, stdcall&"qt_init_noGUI", {I, P}, P),
	hQtRun = define_c_func(hEuQt, stdcall&"qt_run", {I}, I),

	hQtLoadUi = define_c_func(hEuQt, stdcall&"qt_loadUi", {P, CP}, P),
	hQtShow = define_c_proc(hEuQt, stdcall&"qt_show", {P}),
	hQtPropSetString = define_c_func(hEuQt, stdcall&"qt_set_string_prop", {P, CP, CP}, I),
	hQtPropSetBool = define_c_func(hEuQt, stdcall&"qt_set_bool_prop", {P, CP, I}, I),
	hQtPropSetFloat = define_c_func(hEuQt, stdcall&"qt_set_float_prop", {P, CP, F}, I),
	hQtPropSetInteger = define_c_func(hEuQt, stdcall&"qt_set_int_prop", {P, CP, I}, I),

	hQtAcceptDrops = define_c_func(hEuQt, stdcall&"qt_acceptDrops", {P, I}, I),
	hQtPropGetString = define_c_func(hEuQt, stdcall&"qt_get_string_prop", {P, CP}, CP),
	hQtPropGetBool = define_c_func(hEuQt, stdcall&"qt_get_bool_prop", {P,CP}, I),
	hQtPropGetInt = define_c_func(hEuQt, stdcall&"qt_get_int_prop", {P,CP}, I),
	hQtPropGetStruct = define_c_func(hEuQt, stdcall&"qt_get_struct_prop", {P,CP}, CP),
	hQtSetAttribute = define_c_proc(hEuQt, stdcall&"qt_setAttribute", {P, I, I}),
	hQt_display = define_c_proc(hEuQt, stdcall&"qt_display", {P, CP}),

	hQt_setParent = define_c_proc(hEuQt, stdcall&"qt_setParent", {P, P}),
	hQtParentWidget = define_c_func(hEuQt, stdcall&"qt_parentWidget", {P}, P),
	hQtfindChild = define_c_func(hEuQt, stdcall&"qt_findChild", {P,CP,CP}, P),
	hQtConnect = define_c_func(hEuQt, stdcall&"qt_connect", {P, CP, CP, I}, I),
	hQtDisconnect = define_c_func(hEuQt, stdcall&"qt_disconnect", {P, CP, CP},I),
	hQtSetFocus = define_c_proc(hEuQt, stdcall&"qt_setFocus", {P}),
	hQtTr = define_c_func(hEuQt, stdcall&"qt_tr", {P,CP,P,P,I}, P),
	hQtResize = define_c_proc(hEuQt, stdcall&"qt_resize", {P,I,I}),
	hQtMove = define_c_proc(hEuQt, stdcall&"qt_move", {P,I,I}),
	hQtSetWindowIcon = define_c_proc(hEuQt, stdcall&"qt_setWindowIcon", {P,CP}),
	hQtSetWindowTitle = define_c_proc(hEuQt, stdcall&"qt_setWindowTitle", {P,CP}),
	hQtSetTabOrder = define_c_proc(hEuQt, stdcall&"qt_setTabOrder", {P,P,P}),
	hQtAddItems = define_c_proc(hEuQt, stdcall&"qt_addItems", {P,CPP,CP}),
	hQtDestroy = define_c_proc(hEuQt, stdcall&"qt_destroy", {P}),
	hQtSetWindowFlag = define_c_proc(hEuQt, stdcall&"qt_setWindowFlag", {P, I}),
	hQtResetWindowFlag = define_c_proc(hEuQt, stdcall&"qt_resetWindowFlag", {P, I}),

	

	hQtGetChildrenNames = define_c_func(hEuQt, stdcall&"qt_getChildrenNames", {P}, CP),
	hQtGetProps = define_c_func(hEuQt, stdcall&"qt_getProps", {P}, CP),
	hQtGetStyles = define_c_func(hEuQt, stdcall&"qt_getStyles", {}, CP),
	hQtSetStyle = define_c_func(hEuQt, stdcall&"qt_setStyle", {P,CP}, I),
	hQtSetStyleSheet = define_c_func(hEuQt, stdcall&"qt_setStyleSheet", {P,CP}, I),
	hQtActions = define_c_func(hEuQt, stdcall&"qt_actions", {P}, P),
	hQtAddWidget = define_c_func(hEuQt, stdcall&"qt_addWidget", {P,P}, P),
	hQtInvokeMethod = define_c_func(hEuQt, stdcall&"qt_invokeMethod", {P,P,I}, P),
	hQtInherits = define_c_func(hEuQt, stdcall&"qt_inherits", {P,CP}, I),
	$


--**
-- you will normally not need to use this qt instance variable.
-- use instead the window or control returned from findChild or create
--when a routine needs a handle as a parameter
public atom qApp = c_func(hQtApp, {})

--** 
--compiler used and Qt version options plugins at compile time of shared lib

public function version_info()
	atom rstr = c_func(hQtVersion_info, {})
	return peek_string(rstr)
end function

public function widget_info(atom widget)
	atom rstr = c_func(hQtWidget_info, {widget})
	return peek_string(rstr)
end function


--** 
-- returns a global application clipboard object which you can setText or get text from.
-- and other mime types. need more functions. appears to be no properties to set/get text,
--and if want html instead of text or other mime type, or to check isowner of data.

public function clipboard()
	return c_func(hQtClipboard, {})
end function

--** 
-- this is the only way to set text on the clipboard, but may work on
--other objects like lineedit or textedit widgets eventually.
--i this early alpha version of euqt propset text may be more reliable
--as yet not all widget classes are supported with setText() and text()

public procedure setText(atom widget, sequence txt)
	atom pTxt = allocate_string(txt,1)
	c_proc(hQtSetText, {widget, pTxt})
end procedure

public procedure appendText(atom widget, sequence txt)
	atom pTxt = allocate_string(txt,1)
	c_proc(hQtAppendText, {widget, pTxt})
end procedure

--** 
-- this is the only way to get text from the clipboard, but may work on
--other objects like lineedit or textedit widgets

public function text(atom widget)
	atom result = c_func(hQtText, {widget})
	return peek_string(result)
end function

--** 
-- paths to plugins used by Qt and Qt apps

public function plugin_info()
	atom rstr = c_func(hQtPlugin_info, {})
	return peek_string(rstr)
end function



--**
-- initilize qt gui default QApplication_GuiClient. 
-- other options, QApplication_Tty only initilize core functions no GUI
--
-- QApplication_GuiServer may have application in the future.

public function init(sequence argv=command_line(), integer gui=QApplication_GuiClient)
	atom fnVal, pArgv
	integer argc = length(argv)

	pArgv = NULL
	if argc then
		pArgv = allocate_string_pointer_array(argv)
	end if

	if gui=QApplication_GuiClient then
	    
	    fnVal =  c_func(hQtInit, {argc, pArgv})
	else
	    fnVal =  c_func(hQtInit_noGUI, {argc, pArgv})
	end if

	if argc then
		free_pointer_array(pArgv)
	end if

	--possibly set default close?
	--~ QObject::connect(app, SIGNAL(lastWindowClosed()), app, SLOT(quit()));
	return fnVal
end function


--**
--   the once=count will possibly run that many event loops,
--  then continue on to the next statement in the program or exit normally.
-- this may be useful for debugging? if once is non zero will call ProcessEvents()
-- that might be usefil in a non GUI application or in response to external event.
--otherwise is app->exec() full time event loop.

public function run(integer once=0)
	return c_func(hQtRun, {once})
end function


--**
--  will crash on null widget
-- called with an invalid property for that object will attempt to create a new property.
-- see the qt docs, the return value is not entirely reliable for sucess in every case.
-- will set a string an integer or an atom depending on the contents of val

public function propset(atom widget, sequence name, object val)
	if not widget then crash("propget widget not valid") end if
	atom pName = allocate_string(name,1)
	object result = 0

	if sequence(val) then
		atom pVal = allocate_string(val,1)
		result = c_func(hQtPropSetString, { widget, pName, pVal })
		--~ free(pVal)

	elsif integer(val) then
		result = c_func(hQtPropSetInteger, { widget, pName, val })

	elsif atom(val) then
		result = c_func(hQtPropSetFloat, { widget, pName, val })
	end if

	--~ free(pName)
    return result
end function

public function propset_bool(atom widget, sequence name, integer val)
	if not widget then crash("propget widget not valid") end if
	atom pName = allocate_string(name,1)
    return c_func(hQtPropSetBool, { widget, pName, val })
end function


--**
--  not implemeted yet, will expect val to be of the proper form for that property
-- one of QPoint, QSize, QRect QLine and their F variety
public function propset_struct(atom widget, sequence name, object val)
    if not widget then crash("propget widget not valid") end if
    atom pName = allocate_string(name,1)
    object result = 0

    return result
end function

--**
--  get string or any property that works with toString in qt.
-- all propget's will assert crash on null widget.
-- calling with invalid properties may return invalid results.
-- that may change in the future to an optional crash or a warning popup.

public function propget(atom widget, sequence name)
	if not widget then crash("propget widget not valid") end if

	atom pName = allocate_string(name,1)

	atom result = c_func(hQtPropGetString, {widget, pName})
	--~ free(pName)

	return peek_string(result)
end function

--**
--  dupe of getstring/propget not fully working yet for any property, 
-- properties size and pos apparently do not support toString in qt,
-- will return a string {0,0} or whatever for a QPoint or QSize.
-- there is no prop_set_struct yet.
--
--would need to know what structure to return valid results...
--will return the type name if can't return a pretty printed struct.
-- will assert crash on invalid property, unlike the other prop_getters,

public function propget_struct(atom widget, sequence name)
	if not widget then crash("propget widget not valid") end if

	atom pName = allocate_string(name,1)

	atom adrs = c_func(hQtPropGetStruct, {widget, pName})
	
	--eventually find a way to return a valid sequence
	--~ atom result = peek4u(adrs)
	--~ return peek2u({result, 4})

	return peek_string(adrs)
end function

public function propget_bool(atom widget, sequence name)
	if not widget then crash("propget widget not valid") end if
	atom pName = allocate_string(name,1)

	integer result = c_func(hQtPropGetBool, {widget, pName})
	--~ free(pName)

	return result
end function

public function propget_integer(atom widget, sequence name)
	if not widget then crash("propget widget not valid") end if
	atom pName = allocate_string(name,1)

	integer result = c_func(hQtPropGetInt, {widget, pName})
	--~ free(pName)

	return result
end function


--get atom?

--**
--  ui is a qt4 xml format, use the designer to create or edit ui one.
--use read_file for loading ui files to pass into this function.
--
--if there are connections specified in the ui file 
-- a connection will be attempted by Qt to a compatible slot.
--this may not work as from c++ and is currently untested.

public function loadUi(sequence ui, atom parent=0)
	atom pUi = allocate_string(ui,1)
	atom widget = c_func(hQtLoadUi, {pUi, parent})
	--~ free(pUi)

	--if widget then --possibly set default close?
	--~ setAttribute(Qt::WA_DeleteOnClose, true);
	return widget
end function


--**
-- implemented with findChild for locating items in ui files loaded with loadUi.
-- parameter oftype defaults to QWidget but can also find QAction type objects.
--are there other types possible that are not QWidget?

public function findChild(atom parent, sequence name, sequence oftype="QWidget")
	atom pType = allocate_string(oftype,1)
	atom pName = allocate_string(name,1)
	atom widget = c_func(hQtfindChild, {parent, pName,pType})
	--~ free(pName)
	return widget
end function

public function parent(atom widget)
	return c_func(hQtParentWidget, {widget})
end function

public procedure setParent(atom widget, atom parent)
	c_proc(hQt_setParent, {widget, parent})
end procedure

--setParent

--**
--  param 1 is either a widget or a sequence of window/widget handle returned from loadUi
-- and widget to search for by name in the ui. saving a call to findChild.
-- 
--the handler function can receive values, the first is always a widget
--so if for example you have set a handler for toggled() or checked() which
-- will return an integer 1 or 0, then you must also catch the widget parameter.
-- **note** with current version euphoria 4.0 don't use default parameters in function callbacks
-- normally you would be able to just add a coma to skip the first param.
-- <eucode>
-- from the hello example
-- function on_toggled(atom w, integer state)
-- 	puts(1, sprintf("State: %d\n", state))
-- 	return 1
-- end function
-- connect(tb, "toggled(bool)", "slot(bool)", routine_id("on_toggled"))
-- </eucode>
--
-- the type of signal depends on the type of widget
--	*toggled()  for checkboxes radio buttons
--	*clicked()  for push buttons	
--	*triggered()  for actions & menu items
--	*activated()  key event
--	*textChanged() LineEdit 
--
-- not a complete list
--
-- available public slots: from euqt,h
-- these will match the type of signal various classes of widgets emit
-- 	*slot()  return nothing\\
--	   use function handle_xyz()
-- 	*slotWidget()  return only widget\\
--	   use function handle_xyz(atom widget)
-- 	*slot(bool )     widget + bool \\
--	   use function handle_xyz(atom widget, integer b)
-- 	*slot(const QDate &) return widget + year, month, day\\
--	   use function handle_xyz(atom widget, integer y, nteger m, nteger d)
-- 	*slot(int )    return widget + integer\\
--	   use function handle_xyz(atom widget, integer i)
-- 	*slot(const QString & ) return widget + char *\\
--	   use function handle_xyz(atom widget, atom string_pointer)
--
--you can choose to have no parameters as well in a simple handler,
--but adding parameters alone will not cause a signal that isn't overloaded to return those or any parameters.
--
--you don't have to disconnect or destroy at the end of the program

public function connect(object w, sequence signal, sequence slot, integer rid)
	atom
		pSignal = allocate_string("2" & signal,1),
		pSlot = allocate_string("1" & slot,1)

	if sequence(w) then
	    --would be slicker to use map(w) but have to do it manually
	    if length(w) > 2 then
		w = findChild(w[1], w[2], w[3])  --action
	    else
		w = findChild(w[1], w[2])
	    end if
	end if

	--should be just a bool
	integer result = c_func(hQtConnect, { w, pSignal, pSlot, callback(rid) })

	--~ free(pSignal)
	--~ free(pSlot)

    return result
end function



--**
--  experimental, may remove too many connects at this time
-- the c wrapper is not saving a handle to the reciever.

public function disconnect(object w, sequence signal, sequence slot)
	atom
		pSignal = allocate_string("2" & signal,1),
		pSlot = allocate_string("1" & slot,1)

	if sequence(w) then
		w = findChild(w[1], w[2])
	end if

	integer result = c_func(hQtDisconnect, { w, pSignal, pSlot })

    return result
end function


--**
-- delete widget or sequence of widgets. 
--best practice, set widget to null after delete.
-- will be a problem if double delete,
-- or worse, try to reference an already deleted widget.
--could fail if try to delete a widget that qt didn't allocate or some other object.
--will probably try to fix that later.

public function destroy(object w)
    if sequence(w) then
	for x= 1 to length(w) do
		c_proc(hQtDestroy, {w[x]})
	end for
    else
	    c_proc(hQtDestroy, {w})
    end if
    return 0
end function

--**
-- can also be set with the visable property

public procedure show(atom widget)
	c_proc(hQtShow, {widget})
end procedure


public procedure focus(atom w)
	c_proc(hQtSetFocus, {w})
end procedure


--**
-- can also be set with the size property when propset_struct is implemented

public procedure resize(atom w, integer width, integer height)
	c_proc(hQtResize, {w,width,height})
end procedure


--**
-- can also be set with the pos property when propset_struct is implemented

public procedure move(atom w, integer x, integer y)
	c_proc(hQtMove, {w,x,y})
end procedure



--**
--  have to set this in pairs of widgets starting with the first, set a,b then b,c then c,d etc.
--normally the tab order will follow the creation order of the widgets.

public procedure setTabOrder(atom w, atom first, atom second)
	c_proc(hQtSetTabOrder, {w,first, second})
end procedure

--**
-- icon is path to icon.
-- icons are png files, other formats untested
--icons may have to be at or below a size dimention and number of colors
--depending on your window manager, usualy 32x32x32 is a safe bet and under 2k for ico
--png can be larger in every way and will be scaled back to a minumum size set by the widget.
-- ico doesn't work well as a menu item?
--
--made setIcon handle Qmainwindow or Qaction/Qmenu transparently
--and a few other widgets,
--when set the icon on a menu/action item you don't also see text but the tooltip is automatically set anyway
--
--why is set icon underline seperated? and not other routines? may need a continuity overhaul

public procedure setIcon(atom w, object icon)
	atom pIcon
	if sequence(icon) then pIcon=allocate_string(icon,1)
	else pIcon=icon
	end if
	c_proc(hQtSetWindowIcon, {w,pIcon})
end procedure

--**
-- sets window title. it may set the parent window title if called with a sub widget?
--qt can handle setting the title for changed like some editors do, put an ##[asteric]## in the title
--then set the windowModified property. consult the qt docs for the exact details.
-- <eucode>
--    setWindowTitle(win, "[*] QUiViewer")
-- title shows:   QUiViewer
--    propset(win, "windowModified" ,1)
-- title shows: * QUiViewer
-- </eucode>

public procedure setWindowTitle(atom w, object t)
	atom pt
	if sequence(t) then pt=allocate_string(t,1)
	else pt=t
	end if
	c_proc(hQtSetWindowTitle, {w,pt})
end procedure

--**
-- set text for lcd numbers.
--should be able to set text using "value" property but that seems to only work for numbers.
--although might be able to work something out later
--
--digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S, 6, 7, 8, 9/g, 
-- minus, decimal point, A, B, C, D, E, F, h, H, L, o, P, r, u, U, Y, colon, 
-- degree sign (which is specified as single quote in the string) and space. QLCDNumber substitutes spaces for illegal characters.

public procedure display(atom w, object t)
	atom pt
	if sequence(t) then pt=allocate_string(t,1)
	else pt=t
	end if
	c_proc(hQt_display, {w,pt})
end procedure


--**
-- flags can be from the  WindowsFlags QT_* defs or a sequence of them or'ed together
-- the function will move the widget back to the origional position and visibility.
-- see also [[:resetWindowFlag]]

public procedure setWindowFlags(atom w, object flags)
        if sequence(flags) then flags = or_all(flags) end if
	
	--do all the visibilty & move in the c layer, getprop won't work yet
	c_proc(hQtSetWindowFlag, {w,flags})
	
end procedure

--**
-- flags can be from the  WindowsFlags QT_* defs 
-- if flags they will be applied one at a time to remove that flag from the widget.
--named set/resetWindowFlags because that's what it is in Qt

public procedure resetWindowFlags(atom w, object flags)
	
        if sequence(flags) then 
	    for x=1 to length(flags) do
		if atom(flags[x])  then
		    c_proc(hQtResetWindowFlag, {w,flags[x]})
		end if
	    end for
	else
		c_proc(hQtResetWindowFlag, {w,flags})
	end if
	
end procedure


--**
--there are a limited number of arrributes that can be set on a widget.
--if attrs is sequence, each item will call qt_setAttribute with the value of setreset.
--
--there is only bool set/clear or test attibute so is not like a property,
--
public procedure setAttribute(atom w, object attrs, integer setreset=1)
        if sequence(attrs) then 
	    for x=1 to length(attrs) do
		if atom(attrs[x])  then
		  c_proc(hQtSetAttribute, {w,attrs[x], setreset})
		end if
	    end for
	else
		c_proc(hQtSetAttribute, {w,attrs, setreset})
	end if
end procedure


--**
-- create a widget with an event handler and d&d.
--!!make it the parent
public function simpleWidget(atom parent=0)
	return c_func(hQtSimpleWidget, {parent})
end function


--**
-- calls setAcceptDrops if called with zero or positive boolean
--otherwise returns the current state of acceptDrop for the widget
--catching droped or dragged files is not currently working
--
public function acceptDrops(atom widget, integer setreset=-1)
	return c_func(hQtAcceptDrops, {widget, setreset})
end function





--**
--  if inherits(widget, "QWidget") then ...
--
public function inherits(atom widget, sequence aclass)
	atom pAclass = allocate_string(aclass,1)
	return c_func(hQtInherits, {widget, pAclass})
end function


--**
--  The style of the entire application can be set using the QApplication::setStyle() function. It can also be specified by the user of the application, using the -style command-line option:
--   {{{./myapplication -style motif}}}
-- parameter style is a string returned from getStyles available for your system
-- or defined and registered with qt possibly from a plugin

public function setStyle(atom widget, sequence style)
	atom pStyle = allocate_string(style,1)
	return c_func(hQtSetStyle, {widget, pStyle})
end function


--**
--  use read_file or create a a qss style sheet string.
--if widget is 0 then the stylesheet applies to the entire app.

public function setStyleSheet(atom widget, sequence style)
	atom pStyle = allocate_string(style,1)
	return c_func(hQtSetStyleSheet, {widget, pStyle})
end function

--**
--  a coma seperated string of styles available on your system
-- Typically they include "windows", "motif", "cde", "plastique" 
-- and "cleanlooks". Depending on the platform, "windowsxp", 
-- "windowsvista" and "macintosh" may be available. 
-- Note that keys are case insensitive.

public function getStyles()
    return peek_string(c_func(hQtGetStyles, {}) )
end function


--** 
--return a coma seperated list of valid properties for this widget
--no sorting or seperation or labeling from where they are inherited.
--properties are case sensitive.
--!!if name is defined then call getprop? or should it just return the name?

public function getProps(atom widget, sequence name="")
	atom rstr = c_func(hQtGetProps, {widget})
	return peek_string(rstr)
end function



--**
-- pretty print a list of children {objectName, type} for widget.
--Qt 4.5 no longer sets objectName property on every widget dependably.
--but if the ui was created in designer, most of the user entered widgets
--should have a name.
--<eucode>
--	printf(1, "win = %s\n%s\n", {
--	    qt:propget(win ,"objectName")  
--	    ,join(wrap_len(getChildrenNames(win ), 60,1), "\n")
--    })
--</eucode>
--currently skips non named objects and only find QWidget and QAction types
--and a few that inherit those types.

public function getChildrenNames(atom widget)
    return peek_string(c_func(hQtGetChildrenNames, {widget}) )
end function

--**
-- will eventually return a translated version of sourceText
-- returns std/text/format( string args)  string and args are unchanged.
--provided for some complatiblity with converted qt programs.
-- you still must convert the %n parameters used with qt's arg() to sensible specifiers formst requires

public function tr(object s, object args={} , object disambiguation = 0, integer n = -1)
 --~ return sprintf(s, args )
 return format(s, args )
end function





--**
-- ##experimental##
-- not functional yet, treewidget and some objects have addText
--need to work out meta details so can guess object/widget
-- and choose correct what method applies
-- currently hardwired for QCombobox with sequence of one or more strings
-- methods are overloaded for various data types so there may be an optional type
-- and conversion from string to type before add would take place
-- and eventually allow sequences of integer, atom converted automatically
-- instead of sequence, could have a hardwired enium
-- but it would get out of date and require more care to add types.
--expecting to just convert to string with a loose interpretation oftype and let c handle it.
--
--looks like just combo toolbox and listwidget have additems
--treewidget and others can evntually work
--
--values is a sequence of strings or may later convert to strings if not

public procedure addItems(atom widget, sequence values, sequence oftype="QString")
    atom pValues
    if compare(oftype, "QString")=0 then
	    pValues = allocate_string_pointer_array(values)--,1
    else
	crash("only QString supported in addItems")
    end if

    object pOftype
    if sequence(oftype) then 
	pOftype = allocate_string(oftype,1) 
    else pOftype=oftype
    end if
    	c_proc(hQtAddItems, {widget, pValues, pOftype})
    --chg back to cleanup if >eu4r2933
    free_pointer_array(pValues)
end procedure





-- Other core routines that have been placed into seperate files to keep
-- organization.
--

public include common_dialogs.e

